<template>
	<view class="avatar-popup">
		<u-popup
			v-model="show"
			mode="center"
			:closeable="true"
			border-radius="8"
			width="400"
			@close="close">
			<view class="popup-content1">
				<view class="title">设置权限</view>
				<view class="tips">需要设置手机下载文件功能才能保存到您的手机哦，是否马上设置？</view>
				<view class="button-content">
					<u-button
						class="btn"
						open-type="openSetting"
						@opensetting="changeSetting"
						:custom-style="{
							'background': '#56d39d',
							'color': '#fff',
							'height': '80rpx',
							'font-size': '32rpx',
							'border-radius': '8rpx',
							'border': 'none'
						}">前往设置</u-button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default{
		props: {
			'popupShow': {
				default: false,
			},
			'avatarUrl': {
				type: String,
				default: ''
			},
		},
		data(){
			return{
				show: this.popupShow,
			}
		},
		watch: {
			popupShow: {
				immediate: true,
				handler(val, oldValue) {
					this.show = val;
				}
			}
		},
		methods: {
			close(){
				this.$emit('close', false);
			},
			// 设置保存
			changeSetting(e){
				const that = this;
				console.log(e);
				if (e.detail.errMsg === 'openSetting:ok'){
					that.show = false;
					wx.showToast({
						title: '设置成功，请重新保存。',
						icon: 'none',
						duration: 5000
					})
				} else {
					that.show = false;
					uni.showToast({
						title: '保存失败，请重试。',
						icon: 'node',
						duration: 5000
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.popup-content1{
		padding: 0 40rpx 40rpx 40rpx;
		.title{
			height: 90rpx;
			line-height: 90rpx;
			font-size: 32rpx;
		}
		.tips{
			font-size: 24rpx;
			margin-bottom: 28rpx;
		}
		.btn{
      ::before{
        display: none;
      }
      ::after{
        display: none;
      }
    }
	}
</style>
